//
//  MKAPIRequestParam.h
//  MKAPI
//  http请求参数封装，包含有url，method，header请求头以及body参数
//  Created by 苏尚进 on 2022/9/6.
//  Copyright © 2022 moon. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MKAPIDictionary.h"
#import "MKAPIHttpFile.h"

typedef enum : NSUInteger {
    MKAPIHttpRequestMethodGET,
    MKAPIHttpRequestMethodPOST,
    MKAPIHttpRequestMethodHEAD,
    
    MKAPIHttpRequestMethodOPTIONS,
    MKAPIHttpRequestMethodPUT,
    MKAPIHttpRequestMethodPATCH,
    MKAPIHttpRequestMethodDELETE,
    MKAPIHttpRequestMethodTRACE,
    MKAPIHttpRequestMethodCONNECT,
} MKAPIHttpRequestMethod;
NS_ASSUME_NONNULL_BEGIN
@interface NSString(MKAPIHttpRequestMethod)
+ (NSString *)stringWithMKAPIHttpRequestMethod:(MKAPIHttpRequestMethod)httpMethod;
@property(nonatomic,readonly) MKAPIHttpRequestMethod MKAPIHttpRequestMethod;
@end
NS_ASSUME_NONNULL_END

NS_ASSUME_NONNULL_BEGIN

@interface MKAPIRequestParam : NSObject<NSCopying>
@property(nonatomic,strong) NSString *url;//完整的url链接
@property(nonatomic,assign) MKAPIHttpRequestMethod httpMethod;//默认为MKAPIHttpRequestMethodPOST
@property(nonatomic,readonly) NSString *httpMethodString;//返回http的method方法大写字符串，如"POST"
@property(nonatomic,readonly) MKAPIDictionary *headersParam;//http请求的headers参数
@property(nonatomic,readonly) NSString *contentType;
@property(nonatomic,strong,nullable) NSData *HTTPBody;//HTTPBodyStream>HTTPBody
@property(nonatomic,strong,nullable) NSInputStream *HTTPBodyStream;

/// 使用NSURLRequest对象设置自身属性
/// - Parameter request: 系统的请求对象
- (void)setValuesWithRequest:(NSURLRequest *)request;

#pragma mark - NSMutableURLRequest 可设置的属性
@property NSURLRequestCachePolicy cachePolicy;
@property NSTimeInterval timeoutInterval;
@property NSURLRequestNetworkServiceType networkServiceType API_AVAILABLE(macos(10.7), ios(4.0), watchos(2.0), tvos(9.0));

@property BOOL allowsCellularAccess API_AVAILABLE(macos(10.8), ios(6.0), watchos(2.0), tvos(9.0));

@property BOOL allowsExpensiveNetworkAccess API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));

@property BOOL allowsConstrainedNetworkAccess API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));

@property BOOL assumesHTTP3Capable API_AVAILABLE(macos(11.3), ios(14.5), watchos(7.4), tvos(14.5));

@property NSURLRequestAttribution attribution API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0));

/// httpMethod是否支持请求体，当GET、HEAD、DELETE将不支持body参数
/// @param httpMethod httpMethod
+ (BOOL)isHTTPMethodsEncodingParametersInURI:(MKAPIHttpRequestMethod)httpMethod;

@end
NS_ASSUME_NONNULL_END


//Content-Type为application/json：json格式
NS_ASSUME_NONNULL_BEGIN
@interface MKAPIRequestParamJSON : MKAPIRequestParam
@property(nonatomic,readonly) MKAPIDictionary *jsonParam;//dict的json参数
@property(nonatomic,readonly,nullable) NSDictionary *HTTPJsonBody;//返回json格式body参数
@end
NS_ASSUME_NONNULL_END

NS_ASSUME_NONNULL_BEGIN
@interface MKAPIRequestParamJSONArray : MKAPIRequestParam
@property(nonatomic,strong,nullable) NSArray *jsonArrayParam;//自定义的json参数，可为dict，array
@end
NS_ASSUME_NONNULL_END


#import "MKAPIHttpFile.h"
//  Content-Type为multipart/form-data：带附件表单格式或者application/x-www-form-data-urlencoded：无附件表单格式
NS_ASSUME_NONNULL_BEGIN
@interface MKAPIRequestParamForm : MKAPIRequestParam
@property(nonatomic,readonly) MKAPIDictionary *formParam;//key=value参数。如果HttpMethod为GET、HEAD、DELETE，keyValuesParam将添加到url中作为参数
@property(nonatomic,readonly,nullable) NSDictionary *HTTPJsonFormBody;//返回json格式body参数
@end
NS_ASSUME_NONNULL_END

NS_ASSUME_NONNULL_BEGIN
@interface MKAPIRequestParamMultipartForm : MKAPIRequestParamForm
@property(nonatomic,readonly) MKAPIHttpFilesParam *filesParam;//multipart/form-data,application/octet-stream，使用的附件。含有附件时，HttpMethod不能为GET、HEAD、DELETE（都将修为POST）
@end
NS_ASSUME_NONNULL_END


//  Content-Type为application/octet-stream ： 二进制流数据（如常见的文件上传、下载）
NS_ASSUME_NONNULL_BEGIN
@interface MKAPIRequestParamOctetStream : MKAPIRequestParam
@property(nonatomic,strong,nullable) MKAPIHttpFile *fileParam;
@end
NS_ASSUME_NONNULL_END

//直接使用现成的request对象
NS_ASSUME_NONNULL_BEGIN
@interface MKAPIRequestParamOriginRequest : MKAPIRequestParam
@property(nonatomic,strong,nullable) NSURLRequest *originRequest;
@end
NS_ASSUME_NONNULL_END
